const express = require("express");
const userList = require("./data/index.json");
const app = express();
app.use(express.json());
app.use(function(req,res,next){
	console.log("req.headers.origin",req.headers.host);
	if(req.headers.host ==="zhangpeiyue.com:8080"){
		next();
	}else{
		res.json({
			ok:-1,
			msg:"网络连接错误"
		})
	}

})
// 登陆
app.post("/login",(req,res)=>{
	// 接收请求体信息
	const {username,password} = req.body;
	const userInfo = userList.find(v=>v.username === username && v.password===password);
	if(userInfo){
		res.json({
			ok:1,
			userInfo,
			msg:"登陆成功"
		})
	}else{
		res.json({
			ok:-1,
			msg:"账号或密码错误"
		})
	}
})
app.listen(8080,()=>{
	console.log("success");
})